@extends('layouts.admin')
@section("title","创建文章")
@section('style')
    <link rel="stylesheet" href="{{ asset('assets/libs/editor.md/css/editormd.min.css') }}" />
    <style type="text/css">
    .layui-upload-img {
    width: 92px;
    height: 92px;
    margin: 0 10px 10px 0;
    }
    .content{
        height: 1000px;
    }
    </style>
@endsection

@section('content')

 
    <!-- Content Header (Page header) -->
    <section class="content">
    <div class="col-md-9" style="width: 100%">
          <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#activity" data-toggle="tab" aria-expanded="true">基本信息</a></li>
                <li class=""><a href="#timeline" data-toggle="tab" aria-expanded="false">详情</a></li>

            </ul>
            <form class="form-horizontal style-form" action="{{route('admin.article.store')}}" method="POST" enctype="multipart/form-data">
            <div class="tab-content">
                <div class="tab-pane active" id="activity">
                
                {{ csrf_field() }}
                    <div class="box-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="title" id="title" placeholder="文章标题" value="{{old('title')}}">
                                <lable class="error error_title"   style="display: inline-block;">{{$errors->first('description')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">简介</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="description" id="description" placeholder="文章简介" value="{{old('description')}}">
                                <lable class="error error_description"   style="display: inline-block;">{{$errors->first('description')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">作者</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="author" id="author" placeholder="作者" value="{{old('author')}}">
                                <lable class="error error_author"   style="display: inline-block;">{{$errors->first('author')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">浏览数</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="visit_cnt" id="inputEmail3" placeholder="浏览数" value="{!! old('visit_cnt') or "0" !!}">
                                <lable class="error error_visit_cnt"   style="display: inline-block;">{{$errors->first('visit_cnt')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">标签</label>

                            <div class="col-sm-10">
                                @foreach($tag as $v)
                                    <input type="checkbox" name="tag_id[]" id="tag_id" value="{!! $v->id !!}" >{!! $v->name !!}
                                @endforeach
                                <lable class="error error_tag_id"   style="display: inline-block;">{{$errors->first('tag_id')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">选择模块</label>
                            <div class="col-sm-10">
                                <select  multiple="" class="form-control"  name="type">
                                    <option value="news">新闻类</option>
                                    <option value="goods">商品类</option>
                                </select>
                                <lable class="error error_type"   style="display: inline-block;">{{$errors->first('type')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">锁定评论</label>

                            <div class="col-sm-10">
                                <input type="radio" name="post_lock" id="post_lock" value="0" >否
                                <input type="radio" name="post_lock" id="post_lock" value="1" checked="checked">是

                                <lable class="error error_post_lock"   style="display: inline-block;">{{$errors->first('is_category')}}</lable>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">封面图片</label>
                            <div class="col-sm-10">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                                    <div class="layui-upload-list">
                                        <img class="layui-upload-img" id="demo1">
                                        <p id="demoText"></p>
                                    </div>
                                </div>
                                <lable class="error error_first_pic"   style="display: inline-block;">{{$errors->first('first_pic')}}</lable>
                            </div>
                        </div>


                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">详情描述</label>
                            <div class="col-sm-10">
                                <div id="editor">
                                    <textarea  name="content" id="content"  sytle="height:300px" splaceholder="商品详情描述">{{old('content')}}</textarea>
                                </div>
                                
                            </div>
                            <lable class="error error_post_lock"   style="display: inline-block;">{{$errors->first('content')}}</lable>
                        </div>
                     
                    </div>
                
                </div>
              <!-- /.tab-pane -->
                <div class="tab-pane" id="timeline">

                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">套图</label>
                        <div class="col-sm-10">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="test2">多图片上传</button>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="demo2"></div>
                                </blockquote>
                            </div>
                        <lable class="error error_post_lock"   style="display: inline-block;">{{$errors->first('more_pic')}}</lable>
                        </div>
                    </div>
               
                   
                        
                    
               
                </div>
              <!-- /.tab-pane -->


            
              <!-- /.tab-pane -->
                </div>
                <div class="box-footer">
                <button class="btn btn-default" onClick="javascript:history.back()">返回</button>
                <button type="submit" class="btn btn-info pull-right ">提交</button>
              </div>
            </form>
            <!-- /.tab-content -->
            </div>
          <!-- /.nav-tabs-custom -->
    </div>
    <!-- /.content -->

    
    </section>

 


@endsection

@section('script')
    <script src="{{asset('assets/js/jquery.validate.js')}}"></script>
    <script src="{{asset('assets/js/quanxian.js')}}"></script>
    <script type="text/javascript" charset="utf-8" src="{{ asset('assets/libs/editor.md/editormd.min.js') }}"></script>
    <script type="text/javascript">
        testEditor = editormd("editor", {
                // width   : "90%",
                height  : 640,
                syncScrolling : "single",
                path    : "{{ asset('assets/libs/editor.md/lib/') }}/",
                imageUpload : true,
                imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL : "{{ asset('assets/libs/editor.md/examples/php/upload.php') }}",
                toolbarIcons : function() {
                    return ["undo", "redo", "|", "bold", "del", "italic", "quote", "|", "h1", "h2", "h3", "h4", "h5", "h6", "|", "list-ul", "list-ol", "hr", "|", "link", "reference-link", "image", "|", "watch", "preview", "fullscreen", "clear", "search", "|", "help", "info"];
                },
            });

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1',
                url:"{{route('admin.upload.image')}}",
                accept:'file',
                data:{'_token': '{{ csrf_token() }}','type':'article'},
                size:"500",
                before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    //如果上传失败
                    if(res.status = 0){
                        return layer.msg('上传失败');
                    }
                    var id=res.data.id
                    var html="<input name='first_pic'type='hidden'  value="+id+">"
                    $("#test1").prepend(html)
                },
                error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });

            //多图片上传
            upload.render({
                elem: '#test2',
                url:"{{route('admin.upload.image')}}",
                multiple: true,
                accept:'file',
                size:"500",
                data:{'_token': '{{ csrf_token() }}','type':'article'},
                before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                    });
                }
                ,done: function(res){
                    if(res.status = 0){
                        return layer.msg('上传失败');
                    }
                    var id=res.data.id
                    var html="<input name='more_pic[]'type='hidden'  value="+id+">"
                    $("#test2").prepend(html)
                }
            });
        });


    </script>
@endsection